﻿using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;

namespace QLTK.User_Control
{
    public partial class XtraViewall : XtraUserControl
    {
        public XtraViewall()
        {
            InitializeComponent();
            showTop1000();
            
        }

        private void showTop1000()
        {
            try
            {
                splashScreenManagerViewAll.ShowWaitForm();
                toKhaiTableAdapter.Top1000(qLTKDataSet.ToKhai);
                splashScreenManagerViewAll.CloseWaitForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void StripButtonViewAll_Click(object sender, EventArgs e)
        {
            try
            {
                splashScreenManagerViewAll.ShowWaitForm();
                toKhaiTableAdapter.ViewAll(qLTKDataSet.ToKhai);
                splashScreenManagerViewAll.CloseWaitForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void gridViewAll_RowStyle(object sender, RowStyleEventArgs e)
        {
            var view = sender as GridView;
            if (e.RowHandle >= 0)
            {
                string status = view.GetRowCellDisplayText(e.RowHandle, view.Columns["TrangThai"]);
                if (status == "Đã sắp xếp")
                {
                    e.Appearance.BackColor = Color.PowderBlue;
                    e.Appearance.BackColor2 = Color.PowderBlue;
                }
                else if (status == "Đang cho mượn")
                {
                    e.Appearance.BackColor = Color.PeachPuff;
                    e.Appearance.BackColor2 = Color.PeachPuff;
                }
                else if (status == "Chưa bàn giao")
                {
                    e.Appearance.BackColor = Color.Empty;
                    e.Appearance.BackColor2 = Color.Empty;
                }
                else
                {
                    e.Appearance.BackColor = Color.Gainsboro;
                    e.Appearance.BackColor2 = Color.Gainsboro;
                }
            }
        }

        private void gridViewAll_DoubleClick(object sender, EventArgs e)
        {
            var frmDetail = new frmDetail(gridViewAll.GetFocusedDataRow());
            frmDetail.Show();
        }

        private void StripButtonNoDev_Click(object sender, EventArgs e)
        {
            try
            {
                splashScreenManagerViewAll.ShowWaitForm();
                toKhaiTableAdapter.NoDev(qLTKDataSet.ToKhai);
                splashScreenManagerViewAll.CloseWaitForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void StripButtonInStore_Click(object sender, EventArgs e)
        {
            try
            {
                splashScreenManagerViewAll.ShowWaitForm();
                toKhaiTableAdapter.InStore(qLTKDataSet.ToKhai);
                splashScreenManagerViewAll.CloseWaitForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void StripButtonOnLoan_Click(object sender, EventArgs e)
        {
            try
            {
                splashScreenManagerViewAll.ShowWaitForm();
                toKhaiTableAdapter.OnLoan(qLTKDataSet.ToKhai);
                splashScreenManagerViewAll.CloseWaitForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}